﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using WeiTalk.OAuth.Sina;

namespace WeiTalk.OAuth
{
    public delegate void HandleResult(AccessToken accessToken);
    public delegate void HandleExceptionResult(string message);
    
    /// <summary>
    /// 授权认证返回类型
    /// </summary>
    public enum ResponseType
    {
        /// <summary>
        /// Code
        /// </summary>
        Code,
        /// <summary>
        /// Access Token
        /// </summary>
        Token
    }

    /// <summary>
    /// 回调返回类型
    /// </summary>
    public enum DisplayType
    {
        /// <summary>
        /// 默认
        /// </summary>
        Default,
        /// <summary>
        /// 移动界面
        /// </summary>
        Mobile,
        /// <summary>
        /// 弹出窗
        /// </summary>
        Popup,
        /// <summary>
        /// Wap12
        /// </summary>
        Wap12,
        /// <summary>
        /// Wap20
        /// </summary>
        Wap20,
        /// <summary>
        /// Javascript
        /// </summary>
        JS,
        /// <summary>
        /// 刷新框架
        /// </summary>
        ApponWeibo
    }

    public static class Utility
    {
        public static AccessToken AccessToken { get; set; }
        public static string ConsumerKey = "671851455";
        public static string ConsumerSecret = "af6e2e14cc760711375b8310d81d3f7f";

        internal static string BuildQueryString(Dictionary<string, string> parameters)
        {
            List<string> pairs = new List<string>();
            foreach (KeyValuePair<string, string> item in parameters)
            {
                if (string.IsNullOrEmpty(item.Value))
                    continue;

                pairs.Add(string.Format("{0}={1}", Uri.EscapeDataString(item.Key), Uri.EscapeDataString(item.Value)));
            }

            return string.Join("&", pairs.ToArray());
        }
    }
}
